<template>
  <tab-bar>
    <div class="user" slot="main">
      <div class="top">
        <router-link to="/user-info" class="avatar">
          <img :src="Number(userInfo.aac004) === 2 ? './static/images/woman.png' : './static/images/man.png'" alt="">
        </router-link>
        <router-link to="/user-info" class="nickname">{{userInfo.name}}</router-link>
        <div class="func">
          <router-link to="/my-pay/00" class="item">
            <i class="xffont xf-yingyejiaofei"></i>
            <span>我的缴费</span>
          </router-link>
          <router-link to="/my-apply/1" class="item">
            <i class="xffont xf-yewubanli"></i>
            <span>我的办理</span>
          </router-link>
          <router-link to="/my-book" class="item">
            <i class="xffont xf-jianli-copy"></i>
            <span>我的预约</span>
          </router-link>
          <router-link to="/my-file" class="item">
            <i class="xffont xf-renwucundang"></i>
            <span>我的档案</span>
          </router-link>
        </div>
      </div>
      <div class="list">
        <mt-cell :is-link="userInfo.auditStatus !== 1" @click.native="cert" v-if="env === 'app'">
          <i class="xffont xf-renzheng list-icon" slot="icon"></i>
          <span slot="title" class="list-title">{{userInfo.auditStatus === 1 ? '已认证' : userInfo.auditStatus === 2 ? '认证失败' : '未认证'}}</span>
          <span v-if="userInfo.auditStatus !== 1">前往档案认证</span>
          <span v-if="userInfo.auditStatus === 1" style="font-size: .26rem;">{{userInfo.name}}</span>
        </mt-cell>
        <mt-cell is-link to="#/message">
          <i class="xffont xf-zhanneixin list-icon" slot="icon"></i>
          <span slot="title" class="list-title">站内信</span>
        </mt-cell>
        <mt-cell is-link to="#/my-suggest">
          <i class="xffont xf-jianyi list-icon" slot="icon"></i>
          <span slot="title" class="list-title">我的反馈</span>
        </mt-cell>
        <mt-cell is-link to="#/my-letter">
          <i class="xffont xf-jianyi1 list-icon" slot="icon"></i>
          <span slot="title" class="list-title">主任信箱</span>
        </mt-cell>
        <mt-cell is-link to="#/sys">
          <i class="xffont xf-shezhi list-icon" slot="icon"></i>
          <span slot="title" class="list-title">系统设置</span>
        </mt-cell>
      </div>
    </div>
  </tab-bar>
</template>
<script>
  import TabBar from '../../layouts/tab-bar/index.vue'
  import {mapGetters, mapMutations} from 'vuex'
  import {personalRecord} from '../../common/js/util'

  export default {
    computed: {
      ...mapGetters([
        'userInfo'
      ])
    },
    components: {TabBar},
    data() {
      return {
        env: GLOBAL_CONF.ENV
      }
    },
    methods: {
      ...mapMutations({
        setUserInfo: 'SET_USER_INFO'
      }),
      getUserInfo() {
        this.$post('/admin/person/sapi/person/center/my/personInfo/get').then(res => {
          // 更新系统缓存的用户信息
          res.data.aac003 = res.data.name
          res.data.aac002 = res.data.idCard
          res.data.aae005 = res.data.phoneNumber
          this.setUserInfo(Object.assign({}, this.userInfo, res.data))
        })
      },
      // 获取用户认证状态
      getAuthenInfo() {
        /* eslint-disable */
        /*
        * auditStatus String 是 0未审核 1通过 2不通过
        * auditRemark	String	是	审核备注信息
          openId	String	是	认证通过返回用户标识
          archId	String	否	档案 id
          archiveCode	String	否	档案编号
          agencyRetire	String	否	是否正式退休 （0 否 1 是）
          agencySocialization	String	否	是否转社会化 （0 否 1 是）
          agencyOrganize	String	否	是否代管党组织关系（0 否 1是）
          agencyResidence	String	否	是否代管户口（0 否 1 是）
          agencySocial	String	否	是否代管社保保险（0 否 1是）
          agencyAccumulation	String	否	是否代管住房公积金（0 否 1是）
          agencyPension	String	否	是否代管养老保险（0 否 1是）
          agencyMedical	String	否	是否代管医疗保险（0 否 1是）
          personDataOrigin 导入数据来源  1为机要导入
        * */
        // 更新系统缓存的用户信息
        this.$post('/admin/person/sapi/person/center/my/auditStatus/get', {}, null, false).then(res => {
          res.data.auditStatus = Number(res.data.auditStatus)
          this.setUserInfo(Object.assign({}, this.userInfo, res.data))
        })
      },
      // 获取档案状态
      getFileStatus() {
        personalRecord().then(res => {
          this.setUserInfo(Object.assign({}, this.userInfo, {fileStatus: res.status}))
        }).catch(() => {
          this.setUserInfo(Object.assign({}, this.userInfo, {fileStatus: 0}))
        })
      },
      cert() {
        if (this.userInfo.auditStatus !== 1) {
          this.$router.push({name: 'cert'})
        }
      }
    },
    created() {
      this.getUserInfo()
      this.getAuthenInfo()
      this.getFileStatus()
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../common/style/user";
</style>
